// Dom7
var $$ = Dom7;
var col = [[
	{field:'text',title:'查询名称',width:60,
		styler: function(value,row,index){
			if(value) {
				return 'height: 40px;';
			}
		}
	}
]];
// Framework7 App main instance
var app = new Framework7({
	root: '#app', // App root element
	id: 'io.yachtar.app', // App bundle ID
  	name: 'Yachtar', // App name
	theme: 'auto', // Automatic theme detection
	dialog: {
		// set default title for all dialog shortcuts
		title: '提示',
		// change default "OK" button text
		buttonOk: '确认',
	  }
});

// Init/Create main view
var mainView = app.views.create('.view', {
	url: '/'
});

$(document).ready(function(){
	$("#edVill").val("");
	$("#edVillName").val("");
	$("#edBuil").val("");
	$("#edBuilName").val("");
	$("#edCell").val("");
	$("#edCellName").val("");
	$("#edHouseId").val("");
	$("#edHouseName").val("");
	$("#edRoom").val("");
	$("#edRoomName").val("");
	$("#edHouseId").val("");
	var height = $(window).height();
	var width = $(window).width();
	$('.input').css('width',width - 130 - 20);
	$('.div_table').css('width', width - 20);
	$('.div_table').css('margin','0px auto');
	$('#grid-house').css('height', height - 300);
	$('.input').css('height',26);
	$(".mobile-content").css('height',height - 55);
	createDataGrid1("grid-house", "", {
		customAttr : {
			request_type : null,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
			request_pram : null,
			successCallback : function(data) {
	
			}
		},
		columns:col,
		fitColumns:true,
		rownumbers:false,
		showFooter: false,
		singleSelect:true,
		pagination : false
	});
	$("#grid-house").datagrid({onClickRow:function(index,row){
		if (row.texttype=='village') {
			$("#edVill").val(row.textid);
			$("#edVillName").val(row.text);
			$("#edBuilName").click();
		}
		if (row.texttype=='building') {
			$("#edBuil").val(row.textid);
			$("#edBuilName").val(row.text);
			$("#edCellName").click();
		}
		if (row.texttype=='cell') {
			$("#edCell").val(row.textid);
			$("#edCellName").val(row.text);
			$("#edRoomName").click();
		}
		if (row.texttype=='room') {
			$("#edHouseId").val(row.textid);
			$("#edHouseName").val(row.text);
			
			$("#edRoom").val(row.textid);
			$("#edRoomName").val(row.text);
		}
	}});
	$("#btnQuery").click(function(){
		var name=$("#edVillName").val();
		createDataGrid1("grid-house", "", {
			customAttr : {
				request_type : REQUEST_TYPE1014,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
				request_pram : {villagename:name},
				successCallback : function(data) {
		
				}
			},
			columns:col,
			fitColumns:true,
			rownumbers:false,
			showFooter: false,
			singleSelect:true,
			pagination : false
		});
		$("#div-house").css("display","");
		try {
			$("#grid-house").datagrid('scrollTo', 0);
		} catch(e) {
		}
		//点击小区查询按钮清空楼幢单元室号
		$("#edBuil").val("");
		$("#edBuilName").val("");
		$("#edCell").val("");
		$("#edCellName").val("");
		$("#edHouseId").val("");
		$("#edHouseName").val("");
		$("#edRoom").val("");
		$("#edRoomName").val("");
		$("#edHouseId").val("");
	});
	$("#edBuilName").click(function(){
		var villageid=$("#edVill").val();
		createDataGrid1("grid-house", "", {
			customAttr : {
				request_type : REQUEST_TYPE1026,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
				request_pram : {villageid:villageid},
				successCallback : function(data) {
		
				}
			},
			columns:col,
			fitColumns:true,
			rownumbers:false,
			showFooter: false,
			singleSelect:true,
			pagination : false
		});
		$("#div-house").css("display","");
		try {
			$("#grid-house").datagrid('scrollTo', 0);
		} catch(e) {
		}
	});
	$("#edCellName").click(function(){
		var buildingid=$("#edBuil").val();
		createDataGrid1("grid-house", "", {
			customAttr : {
				request_type : REQUEST_TYPE26,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
				request_pram : {buildingid:buildingid},
				successCallback : function(data) {
		
				}
			},
			columns:col,
			fitColumns:true,
			rownumbers:false,
			showFooter: false,
			singleSelect:true,
			pagination : false
		});
		$("#div-house").css("display","");
		try {
			$("#grid-house").datagrid('scrollTo', 0);
		} catch(e) {
		}
	});
	$("#edRoomName").click(function(){
		var buildingid=$("#edBuil").val();
		var cellid=$("#edCell").val();
		createDataGrid1("grid-house", "", {
			customAttr : {
				request_type : REQUEST_TYPE29,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
				request_pram : {buildingid:buildingid,cellid:cellid},
				successCallback : function(data) {
		
				}
			},
			columns:col,
			fitColumns:true,
			rownumbers:false,
			showFooter: false,
			singleSelect:true,
			pagination : false
		});
		$("#div-house").css("display","");
		try {
			$("#grid-house").datagrid('scrollTo', 0);
		} catch(e) {
		}
	});
	
	$("#edVillName").click();
	
	$("#payBtn").click(function() {
		var houseid = $("#edHouseId").val();
		sessionStorage.setItem("houseid", houseid);
		if(houseid == "") {
			$.messager.alert("提示", "请先选择需要缴费的房屋！", "error");
			return;
		}
		call_remote(REQUEST_TYPE1019, {tableName: "V_ARH_HOUSEINFO",flag : "houseid",query: houseid}, function(data){
			if(!(data[0].paymentflag == "0" || data[0].paymentflag == "1")) {
				$.messager.alert("提示", "该房屋已交费，无需再次交费！", "error");
				return;
			}
			if(data[0].housestatus == "DJ") {
				$.messager.alert("提示", "该房屋暂时无法交存，请联系开发商！", "error");
				return;
			}
			if(data[0].housestatus == "ZX") {
				$.messager.alert("提示", "该房屋已注销不可交存！", "error");
				return;
			}
			 window.location.href = "../../plugin/pay/pay.html";	
		});
	});
});

$$('#back').on('click', function () {
	window.location.href = "../../plugin/homepage/homepage.html";
});	
